<?php
/**
 *
 *
 * @author sunjing<sunjing@shopex.cn>
 * @version $Id: tbpresale.php 2016-10-13 17:23Z
 */
class erpapi_shop_response_components_order_tbpresale extends erpapi_shop_response_components_order_abstract
{
    const _APP_NAME = 'ome';

    public function convert()
    {
        if($this->_platform->_ordersdf['order_type'] == 'presale'){
            $this->_platform->_newOrder['order_type'] = 'presale';
            if($this->_platform->_ordersdf['step_trade_status']=='FRONT_PAID_FINAL_NOPAID'){//订单已付尾款未付
                 
                $this->_platform->_newOrder['payed'] = $this->_platform->_ordersdf['step_paid_fee'];
                $this->_platform->_newOrder['pay_status'] =3;
            }
            
        }
    }

    public function update()
    {

        if($this->_platform->_tgOrder['order_type'] == 'presale' && $this->_platform->_ordersdf['step_trade_status'] == 'FRONT_PAID_FINAL_PAID'){
                //查看扩展表里状态是否为1如果为1 需要更新状态
                $order_id = $this->_platform->_tgOrder['order_id'];
                $extendObj = app::get('ome')->model('order_extend');
                $extend = $extendObj->dump(array('order_id'=>$order_id));
                if ($extend['presale_auto_paid']>0 && $extend['presale_pay_status'] == '1'){
                    $extendObj->update(array('presale_auto_paid'=>0,'presale_pay_status'=>'2'),array('order_id'=>$order_id));

                }
        }
        

    }
}